﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Telerik.Windows.Controls.GridView;
using Baosight.ZNH.ZMCM.UI.Utils;
using Baosight.Platform.Core.ServiceModel;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCM.UI.ChildWindows;
using Telerik.Windows.Controls;

/// <summary>
/// Created by 贾雪民 2011-05-27
/// 材料分管设置
/// </summary>
namespace Baosight.ZNH.ZMCM.UI
{
    public partial class ZMCMH0 : EFViewCmes
    {

        public ZMCMH0()
        {
            InitializeComponent();
           base.BeforeAction += OnBeforeAction;
        }

        public override void Initialize(EIInfo initData)
        {
            base.Initialize(initData);
        }
        /// <summary>
        /// 修改前设置属性
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.EFGridCheckedRows = this.grid.GetCheckedEIRows();
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 材料分管设置新增操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnInsertButtonClick(object sender, RoutedEventArgs e)
        {
            EIInfo eiInfo = new EIInfo();
            base.OnInsertButtonClickPopup(eiInfo, "材料分管设置-新增", "insert", null, sender, e);
        }

        /// <summary>
        /// 材料分管设置修改操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            IList<EIRow> _list = this.grid.GetCheckedEIRows() == null ? new List<EIRow>() : this.grid.GetCheckedEIRows();
            EIInfo eiInfo = new EIInfo();
            EIBlock eIBlock = new EIBlock("result");
            EIRow row = new EIRow();
            if (_list.Count > 0)
            {
                row = BaseTools.GetEIRowByOldEIRow(this.EIDataContext.GetBlock("result").GetColumns(),  _list[0]);
            }
            eIBlock.SetRow(0, row);
            eiInfo.AddBlock(eIBlock);
            base.OnUpdateButtonClickPopup(eiInfo, "材料分管设置-修改", "update", null, sender, e);
        }

        /// <summary>
        /// 弹出窗口关闭时执行的方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenWindow_Closed(object sender, WindowClosedEventArgs e)
        {
            if (e.DialogResult == true)
            {
                this.grid.Refresh();//刷新Grid区域
            }
            base.TempButtonOpen(true);//按钮生效
        }

        /// <summary>
        /// 构造新增页面内容、弹出页面
        /// </summary>
        /// <param name="eIInfo"></param>
        /// <param name="title"></param>
        public override void OpenPopup(EIInfo eIInfo, string title, string dialogType, string _args)
        {
            TypeManageMentSet typemanagement = new TypeManageMentSet(dialogType);//构造一个新的修改页面
            typemanagement.EIDataContext = new Platform.Core.UI.EIDataContext();
            eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cm.empName"));
            //eIInfo.AddBlock(this.EIDataContext.GetBlock("cmes.cm.materoalName"));
            typemanagement.EIDataContext.Update(eIInfo);
            if (dialogType.Equals("update"))
            {
                (typemanagement.fdMaterialId.Content as CmesCustomView).Display = (this.grid.GetCheckedEIRows()[0])["fdMaterialName"];
            }
            CmesWindows _popup = new CmesWindows();//构造一个弹出页面
            _popup.ResizeMode = ResizeMode.NoResize;//设置不能修改窗口大小
            _popup.Header = title == null ? "" : title;//设置Title
            _popup.Content = typemanagement;//让新增页面在弹出窗口显示
            _popup.Closed += new EventHandler<WindowClosedEventArgs>(OpenWindow_Closed);
            _popup.ShowDialog();
        }
    }
}
